package controllers;

import java.util.List;

import models.City;
import models.Design;
import models.FeedBack;
import models.Message;
import models.TakeMeTour;
import models.ToursicItem;
import models.Type;
import play.mvc.Controller;

public class Application extends Controller {

	public static void getAllTypes() {
		List<Type> allTypes = Type.findAll();
		renderXml(allTypes);
	}

	public static void getImageByType(int typeId) {
		Type type = Type.findById((long) typeId);
		if (type.image.get() != null) {
			renderBinary(type.image.get());
		} else {
			renderHtml("pas de figure");
		}
	}

	public static void getAllCities() {
		List<City> allCities = City.findAll();
		renderXml(allCities);
	}

	public static void addFeedBack(String message) {
		FeedBack fb = new FeedBack(message);
		fb.save();
	}

	public static void getAllTmt() {
		TakeMeTour takeMeTour = TakeMeTour.find("select tmt from TakeMeTour tmt").first();
		renderXml(takeMeTour);
	}

	public static void getAllTourItemsByType(int typeId) {
		Type type = Type.findById((long) typeId);
		List<ToursicItem> allTourItems = ToursicItem.find("byType", type).fetch();
		renderXml(allTourItems);
	}
	
	public static void getAllTourItemsByTypeAndCity(int typeId, int cityId) {
		Type type = Type.findById((long) typeId);
		System.out.println("ALLO");
		City city = City.findById((long) cityId);
		List<ToursicItem> allTourItems = ToursicItem.find("byCityAndType", city, type).fetch();
		renderXml(allTourItems);
	}

	public static void getAllTourItems() {
		List<ToursicItem> allTourItems = ToursicItem.findAll();
		renderXml(allTourItems);
	}

	public static void getAllMessages() {
		List<Message> listMessages = Message.findAll();
		renderXml(listMessages);
	}

	public static void getTypeByItemId(int idItem) {
		ToursicItem toursicItem = ToursicItem.findById((long) idItem);
		Type type = toursicItem.type;
		renderXml(type);
	}

	public static void getDesign() {
		Design design = Design.find("select d from Design d").first();
		renderXml(design);
	}

	public static void getLogoByDesign(int id) {
		Design design = Design.findById((long) id);
		System.out.println(design.designName);
		if (design.logo.get() != null) {
			renderBinary(design.logo.get());
		} else {
			renderHtml("pas de figure");
		}
	}

	public static void getItemImageOneById(int id) {
		ToursicItem tourItem = ToursicItem.findById((long) id);
		if (tourItem.imageOne.get() != null) {
			renderBinary(tourItem.imageOne.get());
		} else {
			renderHtml("pas de figure");
		}
	}

	public static void getItemImageTwoById(int id) {
		ToursicItem tourItem = ToursicItem.findById((long) id);
		if (tourItem.imageTwo.get() != null) {
			renderBinary(tourItem.imageTwo.get());
		} else {
			renderHtml("pas de figure");
		}
	}

	public static void getItemImageThreeById(int id) {
		ToursicItem tourItem = ToursicItem.findById((long) id);
		if (tourItem.imageThree.get() != null) {
			renderBinary(tourItem.imageThree.get());
		} else {
			renderHtml("pas de figure");
		}
	}
}